import 'package:flutter/material.dart';
import 'package:flutter_kit_plus/flutter_kit.dart';

import '../../commont/button.dart';
import '../../model/model.dart';
import '../../tool/assets.dart';
import 'commont/diaButton.dart';

class SelectCopyView extends BaseDialog {
  ChannelModel ch;
  List<ChannelModel> list;
  void Function(String)? onChange;
  SelectCopyView({super.key, required this.ch, required this.list});

  @override
  BaseDialogState createState() => _SelectCopyView();
}

class _SelectCopyView extends BaseDialogState<SelectCopyView> {
  String select_name = '';
  @override
  Widget buildContent(BuildContext context) {
    return LayoutBuilder(builder: (BuildContext context, BoxConstraints constrains) {
      return Container(
          height: 180,
          width: constrains.maxWidth,
          child: Stack(
            children: [
              const Positioned(
                left: 0,
                right: 0,
                top: 0,
                height: 49,
                child: Center(
                  child: Text(
                    'Please select the object of copy',
                    style: TextStyle(fontSize: 14, color: Colors.black),
                  ),
                ),
              ),
              Positioned(
                left: 10,
                right: 10,
                top: 49,
                child: Container(height: 1.5, color: Colors.black),
              ),
              Positioned(
                left: 10,
                right: 10,
                top: 60,
                height: 90,
                child: GridView.extent(
                  maxCrossAxisExtent: (constrains.maxWidth - 50) / 4.0,
                  mainAxisSpacing: 10,
                  crossAxisSpacing: 10,
                  childAspectRatio: (constrains.maxWidth - 50) / 4.0 / 30.0,
                  children: widget.list.map(($0) {
                    return kTextButton(
                      name: $0.name,
                      fontSize: 14,
                      textColor: select_name == $0.name
                          ? Colors.white
                          : widget.ch.name != $0.name
                              ? Colors.black
                              : Color_disEnable,
                      borderColor: select_name == $0.name
                          ? Color_theme
                          : widget.ch.name != $0.name
                              ? Colors.black
                              : Color_disEnable,
                      groundColor: select_name == $0.name ? Color_theme : Colors.white,
                      enable: widget.ch.name != $0.name,
                      onClick: (p0) {
                        select_name = $0.name;
                        setState(() {});
                      },
                    );
                  }).toList(),
                ),
              ),
              Positioned(
                left: 10,
                right: 10,
                top: 139,
                child: Container(height: 1.5, color: Colors.black),
              ),
              Positioned(
                right: 0,
                top: 139,
                height: 40,
                width: 60,
                child: Diabutton(
                    title: 'OK',
                    onClick: () {
                      Navigator.pop(context);
                      if (widget.onChange != null) {
                        widget.onChange!(select_name);
                      }
                    }),
              ),
              Positioned(
                right: 60,
                top: 139,
                height: 40,
                width: 70,
                child: Diabutton(
                    title: 'Cancel',
                    onClick: () {
                      Navigator.pop(context);
                    }),
              ),
            ],
          ));
    });
  }
}
